package com.godpaper.the2tigers.busniess.AI
{
	import com.godpaper.the2tigers.busniess.managers.PiecesManager;
	import com.godpaper.the2tigers.busniess.managers.PlayerManager;
	import com.godpaper.the2tigers.model.BoardModel;
	import com.godpaper.the2tigers.model.PiecesModel;
	import com.godpaper.the2tigers.util.NumberUtil;
	import com.godpaper.the2tigers.vo.ConductVO;
	
	import de.polygonal.ds.Array2;
	
	import mx.collections.ArrayCollection;

	/**
	 *
	 * This essay is a detailed explanation of one of the most important
	 * data structures ever created for Game Artificial Intelligence. 
	 * The minimax tree is at the heart of almost every board game program in existence.
	 */	
	public class RandomWalkAI extends GameAIBase
	{
		/**
    	 * if(game over in current board position)
         * return winner
         * children = all legal moves for player from this board
         * if(max's turn)
         * return maximal score of calling minimax on all the children
         * else (min's turn)
         * return minimal score of calling minimax on all the children
		 * 
		*/		
		public function RandomWalkAI(gamePosition:Array2) 
		{
			bestMove = new ConductVO();
			moves =  generateMoves(PiecesModel.getInstance().redPiecesCollection,gamePosition);
			if(moves.length<=0)
			{
				PlayerManager.humanWin();//pluge to death.
			}else
			{
				trace("all possbility moves:",moves.toArray().toString());
				var randomStep:int = NumberUtil.randomNumberWithScope(0,moves.length-1);
				trace("randomStep:",randomStep);
				bestMove = moves.getItemAt(randomStep) as ConductVO;
				trace("randomed bestMove:",bestMove.dump());
				applyMovement(bestMove);
			}
		}	
		
		override public function doEvaluation(conductVO:ConductVO):int
		{
			//Todo:doEvaluation about assumpted conductVO;
//			return _positionEvaluation;;
			return Math.random()*100;
		};
		
	}	
	
}
